Fix baselines wrt css values
authorTimm Bäder <mail@baedert.org>
Tue, 27 Jun 2017 11:27:58 +0000 (13:27 +0200)
committerMatthias Clasen <mclasen@redhat.com>
Thu, 20 Jul 2017 01:27:14 +0000 (21:27 -0400)
The reported minimum baseline is for the reported min height, but if the
css min-height is greater than that, we need to account for that fact
when saving the baseline.

Since the reported baseline is relative to the widget's origin, we also
need to add the top values for margin, border and padding to the
reported baseline.

gtk/gtksizerequest.c
gtk/gtkwidget.c

index ea1b7c0663bdfa242a0aef1a65f5cd9ad36803d1..e1baaf1e738313ed2b63c9cc8e20739bba9367ff 100644 (file)
@@ -155,6 +155,8 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
     {
       int adjusted_min, adjusted_natural;
       int adjusted_for_size = for_size;
+      int reported_min_size = 0;
+      int reported_nat_size = 0;
 
       style = gtk_css_node_get_style (gtk_widget_get_css_node (widget));
       get_box_margin (style, &margin);
@@ -180,7 +182,7 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
         {
           push_recursion_check (widget, orientation);
           widget_class->measure (widget, orientation, -1,
-                                 &min_size, &nat_size,
+                                 &reported_min_size, &reported_nat_size,
                                  &min_baseline, &nat_baseline);
           pop_recursion_check (widget, orientation);
         }
@@ -214,16 +216,14 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
           widget_class->measure (widget,
                                  orientation,
                                  adjusted_for_size,
-                                 &min_size, &nat_size,
+                                 &reported_min_size, &reported_nat_size,
                                  &min_baseline, &nat_baseline);
           pop_recursion_check (widget, orientation);
 
         }
 
-      /* TODO: Baselines */
-
-      min_size = MAX (0, MAX (min_size, css_min_size)) + css_extra_size;
-      nat_size = MAX (0, MAX (nat_size, css_min_size)) + css_extra_size;
+      min_size = MAX (0, MAX (reported_min_size, css_min_size)) + css_extra_size;
+      nat_size = MAX (0, MAX (reported_nat_size, css_min_size)) + css_extra_size;
 
       if (G_UNLIKELY (min_size > nat_size))
         {
@@ -306,8 +306,19 @@ gtk_widget_query_size_for_orientation (GtkWidget        *widget,
              nat_baseline = -1;
            }
          else
-            gtk_widget_adjust_baseline_request (widget, &min_baseline, &nat_baseline);
-       }
+            {
+              if (css_min_size > reported_min_size)
+                {
+                  min_baseline += (css_min_size - reported_min_size) / 2;
+                  nat_baseline += (css_min_size - reported_min_size) / 2;
+                }
+
+              min_baseline += margin.top + border.top + padding.top;
+              nat_baseline += margin.top + border.top + padding.top;
+
+              gtk_widget_adjust_baseline_request (widget, &min_baseline, &nat_baseline);
+            }
+        }
 
       _gtk_size_request_cache_commit (cache,
                                       orientation,
index c477520b4db0909117e2d0bfd69a6e6854c135e8..81f6fdd38cc05ec963186c204202ca423bc867b8 100644 (file)
@@ -5557,7 +5557,6 @@ gtk_widget_size_allocate_with_baseline (GtkWidget     *widget,
                            margin.right + border.right + padding.right;
   real_allocation.height -= margin.top + border.top + padding.top +
                             margin.bottom + border.bottom + padding.bottom;
-  /* TODO: Baseline! */
 
   priv->allocated_baseline = baseline;
   if (g_signal_has_handler_pending (widget, widget_signals[SIZE_ALLOCATE], 0, FALSE))